<%- include ('../public/page_header.ejs')%>
<script type="text/javascript" src="/static/admin/js/jqPaginator.js"></script>
<div class="panel panel-default">              
    <div class="panel-heading">
        <a href="/<%=config.adminPath%>/goods/add" class="btn btn-primary">增加商品</a>
    </div>

    <!-- 搜索框 -->
    <div class="panel-body">
      <form role="form" class="form-inline" method="get" action="/<%=config.adminPath%>/goods">
          <div class="form-group">
              <label for="name">输入关键词</label>
              <input type="text" class="form-control" value="<%= keyword %>" id="keyword" name="keyword" placeholder="请输入名称">
          </div>

          <div class="form-group">
              <button type="submit" class="btn btn-default">开始搜索</button>
          </div>
      </form>
    </div>


    <div class="panel-body">
<!--
列表展示
-->
    <div class="table-responsive">
        <table class="table table-bordered">
            <thead>                                   
            <tr class="th">
                <th>商品名称</th>
                <th>价格</th>  
                <th>点击量</th>
                <th>上架</th>

                <th>热销</th>
                <th>精品</th>
                <th>新品</th>
                <th>推荐排序</th>
                <th>库存</th>                             
                <th class="text-center">操作</th>
            </tr>
            </thead>
            <tbody>
              <% for(var i=0;i<goodsList.length;i++) { %>
                <tr>
                  <td><%= goodsList[i].title %></td>
                  <td><%= goodsList[i].shop_price %></td>
                  <td><%= goodsList[i].click_count %></td>
                  
                  <td class="text-center">
                    <% if(goodsList[i].status==1) { %>
                      <img src="/static/admin/images/yes.gif" onclick="app.changeStatus(this, 'goods','status', '<%= goodsList[i]._id %>', '<%=config.adminPath%>')" />
                    <% } else { %>
                      <img src="/static/admin/images/no.gif" onclick="app.changeStatus(this, 'goods','status', '<%= goodsList[i]._id %>', '<%=config.adminPath%>')"/>
                    <% } %>
                  </td>

                  <td class="text-center">
                    <% if(goodsList[i].is_hot==1) { %>
                      <img src="/static/admin/images/yes.gif" onclick="app.changeStatus(this, 'goods','is_hot', '<%= goodsList[i]._id %>', '<%=config.adminPath%>')" />
                    <% } else { %>
                      <img src="/static/admin/images/no.gif" onclick="app.changeStatus(this, 'goods','is_hot', '<%= goodsList[i]._id %>', '<%=config.adminPath%>')"/>
                    <% } %>
                  </td>

                  <td class="text-center">
                    <% if(goodsList[i].is_best==1) { %>
                      <img src="/static/admin/images/yes.gif" onclick="app.changeStatus(this, 'goods','is_best', '<%= goodsList[i]._id %>', '<%=config.adminPath%>')" />
                    <% } else { %>
                      <img src="/static/admin/images/no.gif" onclick="app.changeStatus(this, 'goods','is_best', '<%= goodsList[i]._id %>', '<%=config.adminPath%>')"/>
                    <% } %>
                  </td>

                  <td class="text-center">
                    <% if(goodsList[i].is_new==1) { %>
                      <img src="/static/admin/images/yes.gif" onclick="app.changeStatus(this, 'goods','is_new', '<%= goodsList[i]._id %>', '<%=config.adminPath%>')" />
                    <% } else { %>
                      <img src="/static/admin/images/no.gif" onclick="app.changeStatus(this, 'goods','is_new', '<%= goodsList[i]._id %>', '<%=config.adminPath%>')"/>
                    <% } %>
                  </td>

                  <td class="text-center">
                    <span onclick="app.editNum(this,'goods','sort','<%=goodsList[i]._id%>', '<%=config.adminPath%>')">
                      <%= goodsList[i].sort %>
                    </span>
                  </td>

                  <td class="text-center">
                    <span onclick="app.editNum(this,'goods','goods_number','<%=goodsList[i]._id%>', '<%=config.adminPath%>')">
                      <%= goodsList[i].goods_number %>
                    </span>
                  </td>

                  <td class="text-center">
                    <a href="/<%= config.adminPath%>/goods/edit?_id=<%=goodsList[i]._id%>">修改</a>　　
                    <a  class="delete" href="/<%= config.adminPath%>/goods/delete?_id=<%=goodsList[i]._id%>&model=Goods">删除</a>
                  </td>
                </tr>  
              <% } %>
            </tbody>
        </table>

        <!-- 分页 -->
        <div class="pagination fr" id="pagination">

        </div>

    </div>
</div>
</div>

<script>
  $(function(){
    var totalPages = parseInt('<%= totalPages %>');
    var page = parseInt('<%= page %>');

    $('#pagination').jqPaginator({
      totalPages: totalPages,
      visiblePages: 10,
      currentPage: page,
      onPageChange: function (num, type) {
        // console.log(num, type) // type  [change,init]
        // $('#text').html('当前第' + num + '页');
        if (type == 'change') {
          location.href = "/<%= config.adminPath%>/goods?page=" + num + "&keyword=<%=keyword%>"
        }
  
      }
    })
  })

</script>

</body>
</html>